/**
 * Application Application.java
 */

package CCT220_Aula17_Exercicio02_13106;


import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JFrame;
import javax.swing.JOptionPane;


/**
 * </br>******************************
 * </br>Project: CCT220
 * </br>Package: CCT220_Aula17_Exercicio02_13106
 * </br>Class: Application
 * </br>Last Change: 26/10/2011 20:50:02 by marcel
 * </br>Description:
 * </br>******************************</br>
 * 
 * @author marcel
 * @author 13106
 * 
 */
public class Application {
	public static void main(String[] args) {

		JFrame jf = new JFrame("Marcel M. Grilo - 13106");
		jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jf.setSize(200, 100);
		jf.setVisible(true);
		jf.addWindowListener(new WindowListener() {
			@Override
			public void windowOpened(WindowEvent e) {

			}


			@Override
			public void windowIconified(WindowEvent e) {

			}


			@Override
			public void windowDeiconified(WindowEvent e) {

			}


			@Override
			public void windowDeactivated(WindowEvent e) {

			}


			@Override
			public void windowClosing(WindowEvent e) {

				Object[] options = { "SIM", "NAO" };
				int opUser = JOptionPane.showOptionDialog(e.getComponent(),
				        "Deseja realmente sair?", "Atencao",
				        JOptionPane.DEFAULT_OPTION,
				        JOptionPane.QUESTION_MESSAGE, null, options, null);
				if (opUser == 0) {
					((JFrame) e.getComponent())
					        .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				} else {
					((JFrame) e.getComponent())
					        .setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

				}

			}


			@Override
			public void windowClosed(WindowEvent e) {

			}


			@Override
			public void windowActivated(WindowEvent e) {

			}
		});
	}
}
